<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.example.model.User" %>
<!DOCTYPE html>
<html>
<head>
    <title>User List</title>
</head>
<body>
<h2>User List</h2>
<a href="add.jsp">Add New User</a>
<table border="1">
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Email</th>
        <th>Action</th>
    </tr>
    <%
        List<User> userList = (List<User>) request.getAttribute("users");
        if (userList != null && !userList.isEmpty()) {
            for (User user : userList) {
    %>
    <tr>
        <td><%= user.getId() %></td>
        <td><%= user.getName() %></td>
        <td><%= user.getEmail() %></td>
        <td>
            <a href="UserController?action=edit&id=<%= user.getId() %>">Edit</a>
            <a href="UserController?action=delete&id=<%= user.getId() %>">Delete</a>
        </td>
    </tr>
    <% } %>
    <% } else { %>
    <tr>
        <td colspan="4">No users found.</td>
    </tr>
    <% } %>
</table>
</body>
</html>